<?php
class DistributorFactory {
	private static $instance;
	private $distributorList;
	
	private function __construct() {
	}
	
	static public function getInstance() {
		if (!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c();
		}
		
		return self::$instance;	
	}

	// Prevent users to clone the instance
	public function __clone() {
		trigger_error('Clone is not allowed.', E_USER_ERROR);
	}
	
	public function register($destination_id, BaseDistributor $distributor) {
		if (isset($this->distributorList[$destination_id])) {
			trigger_error("Format {$destination_id} is already registered. " . var_export($this->distributorList[$destination_id], 1));
		}
		$this->distributorList[$destination_id] = $distributor;
	}

	public function getDistributor($destination_id) {
		if (isset($this->distributorList[$destination_id])) {
			return $this->distributorList[$destination_id];
		}
		
		return FALSE;
	}
}
?>
